<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(function() {
		parent.$.messager.progress('close');
		$('#form').form({
			url : '/messageTemplateController/add',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var typeId = $("#typeId").combobox('getValue');
				if (!typeId) {
					parent.$.messager.alert('提示', '请选择短信类型！', 'info');
					parent.$.messager.progress('close');
					return false;
				}
				var isValid = $(this).form('validate');
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
					parent.$.modalDialog.handler.dialog('close');
				} else {
					parent.$.messager.alert('错误', result.msg, 'error');
				}
			}
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<form id="form" method="post">
			<table class="table table-hover table-condensed">
				<tr>
					<th>短信类型</th>
					<td>
						<select id="typeId" name="typeId" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('setValue','');}}]">
							<c:forEach items="${types}" var="types">
								<option value="${types.id}">${types.name}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<c:if test="${ isSuperadmin}">
					<tr>
							<th>所属小区</th>
							<td>
								<select id="residenceId" name="residenceId" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('setValue','');}}]">
									<c:forEach items="${residence}" var="residence">
										<option value="${residence.id}">${residence.name}</option>
									</c:forEach>
								</select>
							</td>
						</tr>
				</c:if>
				<tr>
					<th>模版内容</th>
					<td><textarea name="content" class="easyui-validatebox span2" data-options="required:true" cols="50" rows="5"></textarea><span>{*}内表示需填充的字段</span></td>
				</tr>
				<tr>
					<th>是否启用：</th>
					<td>
						停用：<input type="radio" name="isUsed" value="0" />&nbsp;&nbsp;
						启用：<input type="radio" name="isUsed" value="1" checked="checked" />
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>